import { login, LoginForm } from "@/apis";
import { getToken, setToken } from "@/utils";
import { defineStore } from "pinia";

export const useUserStore = defineStore("user", {
  state: () => ({
    token: getToken() || "",
  }),
  actions: {
    async login(userInfo: LoginForm) {
      const { data } = await login(userInfo);
      this.token = data.token;
      setToken(data.token);
    },
  },
});

export default useUserStore;
